layui.use(['form', 'element', 'jquery'], () => {
    let form = layui.form, $ = layui.jquery;
    getAdmin((data) => {
        for (let elem of profileForm) {
            let name = elem.name, type = elem.type;
            // 表单控件name不为空和与之相匹配的单元格数据不为空
            if (!isEmpty(name) && !isEmpty(data[name])) {
                let value = data[name];
                if (type === "text" || type === "password" || type === "hidden") {
                    elem.value = value;
                } else if (type === "radio" && elem.value === value) {
                    $(elem).next().click();
                } else if (type === "checkbox" && value === "banned") {
                    $(elem).attr("checked", true);
                }
            }
        }
    });
    upload("#upload_btn", "/admin/upload");
    form.on('submit(formSubmit)', function (data) {
        let succeedUploadPath = sessionStorage.getItem("succeedUploadPath");
        if (!isEmpty(succeedUploadPath)) {
            data.field.headImg = JSON.parse(succeedUploadPath)[0];
            sessionStorage.removeItem("succeedUploadPath");
        }
        let params = filterFormOnNull(data.field);
        ajax("/back/admin/changeProfile", "POST", params, (res) => {
            let icon = res.code === 0 ? 1 : 2;
            layer.msg(res.msg, {icon: icon, offset: 'rt'});
            window.parent.location.reload();
        });
        return false;
    });
});